<?php

use kartik\form\ActiveForm;
use common\models\Category;
use common\models\Hotel;
use trntv\filekit\widget\Upload;
use vova07\imperavi\Widget;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Url;

$categoryItems = ArrayHelper::map(Category::find()->all(), 'id', 'cate_name');

$hotelItems = ArrayHelper::map( Hotel::find()->all(), 'id', 'name');

/* @var $this yii\web\View */
/* @var $model common\models\Goods */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="goods-form">

    <?php $form = ActiveForm::begin([
        'type' => ActiveForm::TYPE_HORIZONTAL,
        'formConfig' => ['labelSpan' => 2, 'deviceSize' => ActiveForm::SIZE_SMALL]
    ]); ?>

    <div class="nav-tabs-custom">
        <!-- Tabs within a box -->
        <ul class="nav nav-tabs ui-sortable-handle">
            <li class="active"><a href="#base" data-toggle="tab" aria-expanded="false">基础</a></li>
            <li class=""><a href="#extend" data-toggle="tab" aria-expanded="true">属性</a></li>
        </ul>
        <div class="tab-content">
            <div class="chart tab-pane active" id="base">

                <?= $form->field($model, 'cate_id')->dropDownList($categoryItems, ['prompt' => '选择分类...']) ?>

                <?= $form->field($model, 'hotel_id')->dropDownList($hotelItems, ['prompt' => '选择关联酒店...']) ?>

                <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

                <?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>

                <?= $form->field($model, 'thumb')->widget( Upload::className(), [
                    'url'=>['upload'],
                    'acceptFileTypes' => 'png|jpeg|jpg|gif',
                    'maxFileSize'=>3 * 1024 * 1024, // 3 MiB
                ]) ?>

                <?= $form->field($model, 'attachments')->widget( Upload::className(), [
                    'url'=>['upload'],
                    'multiple' => true,
                    'sortable'=>true,
                    'acceptFileTypes' => 'png|jpeg|jpg|gif',
                    'maxFileSize'=>3 * 1024 * 1024, // 3 MiB
                    'maxNumberOfFiles'=>10
                ]) ?>

                <?= $form->field($model, 'price', [
                    'addon' => [
                        'append' => ['content'=>'.00'],
                    ],
                ])->textInput() ?>

                <?= $form->field($model, 'accommodate', [
                    'addon' => [
                        'append' => ['content'=>'人'],
                    ],
                ])->textInput() ?>

                <?= $form->field($model, 'acreage', [
                    'addon' => [
                        'append' => ['content'=>'㎡'],
                    ],
                ])->textInput() ?>

                <div class="form-group field-venue-size required">
                    <label class="col-sm-2 control-label" for="venue-acreage">场地尺寸</label>
                    <div class="input-group col-sm-10" style="padding:0 15px">
                        <div class="row">
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <?= Html::activeTextInput($model, 'size[length]', ['class' => 'form-control']) ?>
                                    <div class="input-group-addon">长</div>
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <?= Html::activeTextInput($model, 'size[width]', ['class' => 'form-control']) ?>
                                    <div class="input-group-addon">宽</div>
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <?= Html::activeTextInput($model, 'size[height]', ['class' => 'form-control']) ?>
                                    <div class="input-group-addon">高</div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-offset-2 col-sm-10"><div class="help-block"></div></div>
                </div>

                <?= $form->field($model, 'content')->widget(Widget::className(),
                    [
                        'settings'=>[
                            'lang' => 'zh_cn',
                            'minHeight'=>400,
                            'maxHeight'=>400,
                            'plugins' => [
                                'fontsize',
                                'clips',
                                'fullscreen',
                                'fontcolor',
                                'video',
                                'table',
                            ],
                            'buttonSource'=>true,
                            'convertDivs'=>false,
                            'removeEmptyTags'=>false,
                            'imageUpload'=> Url::to(['uploadFile'])
                        ]
                    ]
                ) ?>

            </div>

            <div class="tab-pane" id="extend">
                <?= \common\widgets\FormAttributeMultiple::widget([
                    'model' => $model,
                    'attribute' => 'goodsAttributes',
                    'attributeItems' => \common\models\Attribute::find()->where(['model_id' => 2])->all(),
                ])?>
            </div>
        </div>
    </div>


    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <?= Html::submitButton($model->isNewRecord ? '创建' : '更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
        </div>
    </div>

    <?php ActiveForm::end(); ?>

</div>
